unit Recordation;

interface
procedure printList(head : pelement);
procedure addtoEnd(var head : pelement; num : integer);
procedure AddToBegin(var head : pelement; num : integer);
procedure DelFromBegin (head : pelement);
procedure DelFromEnd(head : pelement);
implementation
procedure printList(head : pelement);
var
  current : pelement;
begin
  current := head;
  while (current <> nil) do
  begin
    writeln(current^.value);
    current := current^.next;
  end;
end;
procedure addtoEnd(var head : pelement; num : integer);
var
  current : pelement;
begin
  if (head <> nil) then
  begin
    current := head;
    while (current^.next <> nil) do
      current := current^.next;
    new(current^.next);
    current^.next^.value := num;
    current^.next^.next := nil;
  end
  else AddToBegin(head, num);
end;
procedure AddToBegin(var head : pelement; num : integer);
var
  tmp : pelement;
begin
  tmp := head;
  new(head);
  head^.value := num;
  head^.next := tmp;
end;
procedure DelFromBegin (head : pelement);
var
temp : pelement;
begin
  head := head^.next;
  temp := head^.next;
  dispose(head);
  head := temp;
end;
procedure DelFromEnd(head : pelement);
var
current : pelement;
begin
  current := head;
  while (current^.next^.next <> nil) do
    current := current^.next;
  current^.next := nil
  dispose(current^.next^.next);
end;


end.
 